#pragma once
#include <iostream>
using namespace std;
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

const string gpipeFile = "./fifo";
const mode_t gmode = 0600;
const int gdefaultfd = -1;
const int gsize = 1024;
const int gForRead = O_RDONLY;
const int gForWrite = O_WRONLY;
int OpenPipe(int flag)
{
    //如果读端打开文件时，写端还没打开，open就会阻塞（可以想象为同时连接管道）
    int fd = ::open(gpipeFile.c_str(), flag);
    if (fd < 0)
    {
        cerr << "open error" << endl;
        return fd;
    }
    return fd;
}

void ClosePipeT(int fd)
{
    if (fd >= 0)
        ::close(fd);
}
